/*
	Author: Superxpdude

	Description:
	Handle point checks and vehicle creation for purchased vehicles.

	Parameter(s):

		0: Object - Player Unit
		1: Type of vehicle to create (number referencing internal array)


	Returns:
	NOTHING
*/
// Define variables
private ["_player","_vecstring","_playerUID","_vectype","_veccost","_playerPoints","_vecpos","_vehicle"];
_player = _this select 0;
_vecstring = _this select 1;
_playerUID = getPlayerUID _player;
_vecstring = toLower _vecstring;

switch (_vecstring) do {
	case "pawnee" : { _vectype = "B_Heli_Light_01_armed_F"; _veccost = 50; };
	case "blackfoot" : { _vectype = "B_Heli_Attack_01_F"; _veccost = 100; };
	case "buzzard" : { _vectype = "I_Plane_Fighter_03_CAS_F"; _veccost = 150; };
	case "wipeout" : { _vectype = "B_Plane_CAS_01_F"; _veccost = 250; };
};

_playerPoints = pointsLogic getVariable [_playerUID, 0];
if (_playerPoints < _veccost) exitWith {};

switch (true) do {
	case (count (nearestObjects [vehiclestore1,["AllVehicles"], 10]) == 0): {_vecpos = (getPosATL vehiclestore1);};
	case ((count (nearestObjects [vehiclestore2,["AllVehicles"], 10]) == 0) and (count (nearestObjects [vehiclestore1,["AllVehicles"], 10]) > 0)): {_vecpos = (getPosATL vehiclestore2);};
	default {_vecpos = nil;};
};

if (isNil "_vecpos") exitWith {};

_playerPoints = _playerPoints - _vecCost;
pointsLogic setVariable [_playerUID, _playerPoints, true];

_vecPos = [(_vecPos select 0), (_vecPos select 1), (_vecPos select 2) + 0.5];


_vehicle = createVehicle [_vectype, _vecpos, [], 0, "NONE"];
_vehicle lock 2;
_vehicle allowDamage false;
_vehicle setVariable ["owner", _playerUID, true];
_vehicle setDir 134;
[[[_vehicle],"scripts\vehicle\setupUnit.sqf"],"BIS_fnc_execVM",nil,true] call BIS_fnc_MP;
_vehicle lock 0;

//_player action ["getInDriver", _vehicle];
[[_player, _vehicle], "SXP_fnc_getIn", _player, false] call BIS_fnc_MP;

sleep 5;
_vehicle allowDamage true;


